from selenium import webdriver
import os

driver = webdriver.Chrome()

url = os.path.join(os.path.abspath('html'), 'frame.html')
driver.get(url)

# 元素定位
# 定位frame中元素
print(driver.find_element_by_tag_name('h3').get_attribute('outerHTML'))
print('--'*20)

# 定位inner元素 将定位不到
# print(driver.find_element_by_id('inner_h3'))

# 切换到inner driver.switch_to.frame(frame) id name 标签
# driver.switch_to.frame('f1')  # id
driver.switch_to.frame('inner')

print(driver.find_element_by_id('inner_h3').get_attribute('outerHTML'))


# 定位到inner_sub
# driver.switch_to.frame('f2')
f2_iframe_element = driver.find_element_by_id('f2')
driver.switch_to.frame(f2_iframe_element)
print(driver.find_element_by_id('p1').get_attribute('outerHTML'))

# 返回父级
